package com.houweishi.module.currency.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.currency.domain.OaCurrency;
import com.houweishi.module.currency.domain.OaCurrencyApproval;
import com.houweishi.module.currency.service.IOaCurrencyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 通用申请事项管理Controller
 * 
 * @author houweishi
 * @date 2023-02-21
 */
@RestController
@RequestMapping("/module/currency")
public class OaCurrencyController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(OaCurrencyController.class);
    @Autowired
    private IOaCurrencyService oaCurrencyService;

    /**
     * 查询通用申请事项管理列表
     */
    @PreAuthorize("@ss.hasPermi('module:currency:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaCurrency oaCurrency)
    {
        startPage();
        List<OaCurrencyApproval> list = oaCurrencyService.selectOaCurrencyApprovalList(oaCurrency);
        return getDataTable(list);
    }

    /**
     * 导出通用申请事项管理列表
     */
    @PreAuthorize("@ss.hasPermi('module:currency:export')")
    @Log(title = "通用申请事项管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaCurrency oaCurrency)
    {
        List<OaCurrency> list = oaCurrencyService.selectOaCurrencyList(oaCurrency);
        ExcelUtil<OaCurrency> util = new ExcelUtil<OaCurrency>(OaCurrency.class);
        util.exportExcel(response, list, "通用申请事项管理数据");
    }

    /**
     * 获取通用申请事项管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:currency:query')")
    @GetMapping(value = "/{currencyId}")
    public AjaxResult getInfo(@PathVariable("currencyId") Long currencyId)
    {
        return success(oaCurrencyService.selectOaCurrencyByCurrencyId(currencyId));
    }

    /**
     * 新增通用申请事项管理
     */
    @PreAuthorize("@ss.hasPermi('module:currency:add')")
    @Log(title = "通用申请事项管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaCurrency oaCurrency)
    {
        try {
            return oaCurrencyService.insertOaCurrency(oaCurrency);
        } catch (Exception e) {
            LOGGER.error("新增通用申请事项管理失败",e);
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改通用申请事项管理
     */
    @PreAuthorize("@ss.hasPermi('module:currency:edit')")
    @Log(title = "通用申请事项管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaCurrency oaCurrency)
    {
        return toAjax(oaCurrencyService.updateOaCurrency(oaCurrency));
    }

    /**
     * 删除通用申请事项管理
     */
    @PreAuthorize("@ss.hasPermi('module:currency:remove')")
    @Log(title = "通用申请事项管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{currencyIds}")
    public AjaxResult remove(@PathVariable Long[] currencyIds)
    {
        return toAjax(oaCurrencyService.deleteOaCurrencyByCurrencyIds(currencyIds));
    }
}
